export default {
	data() {
		return {
			nickName: "点击登录",
			touxiang: "",
			loginStatus: this.Reques.isLogin,
			title: "",
			bodtyH:this.bodtyH-this.CustomBar,
			StatusBar: this.StatusBar,
			CustomBar: this.CustomBar,
			menuArrow: true,
			gridCol: 3,
			gridBorder: false,
			initCode: "",
			cuIconList: {
				order: [{
						cuIcon: 'pay',
						color: 'red',
						badge: 0,
						type: 1,
						showS: true,
						name: '待付款'

					}, {
						cuIcon: 'send',
						color: 'orange',
						badge: 0,
						type: 2,
						showS: true,
						name: '已完成'
					},
					{
						cuIcon: 'send',
						color: 'orange',
						badge: 0,
						type: 4,
						showS: true,
						name: '已取消'
					}
				],
				list: [{
						title: '我的课程',
						icon: 'edit',
						color: "green",
						hasDiscount: 0,
						showS: true,
						url: '/pages/mycourse/mycourse'
					},
					{
						title: '我的红包',
						icon: 'redpacket',
						color: "red",
						hasDiscount: 0,
						showS: true,
						url: '/pages/component/home'
					},
					{
						title: '我的优惠券',
						icon: 'recharge',
						color: "red",
						hasDiscount: 0,
						showS: true,
						url: '/pages/view/coupon'
					},
					{
						title: '联系客服',
						icon: 'servicefill',
						color: "red",
						showS: true,
						hasDiscount: -1,
						url: '0'
					}
			

				]

			}

		}

	},
	mounted() {
		this.loadData();
	},
	methods: {
		/**
		 * 重新登录
		 */
		reLogin() {
			this.Reques.reLogin().then((res) => {
				this.Reques.showToast(res.msg);
				if (res.code == 0) {
					uni.navigateTo({
						url: '/pages/index/index',
						animationType: 'slide-in-top'

					});
				}

				console.log("登录信息 ： " + res);
			}, (err) => {
				this.Reques.showToast(res.msg);
				console.log("登录信息 " + err);
			});

		},



		/**
		 * 更新数据
		 * @param {Object} data
		 */
		upadteVue() {
			this.loadData();

		},
		/**
		 * 加载个人中的数据
		 */
		loadData() {
			let data = {
				action: "getOrderSummary",
				openId: this.Reques.sessionData.data.openId,
			};
			this.initCode = this.Reques.sessionData.data.inviteCode;
			this.Reques.commonQuest('xcx/order.api.php', 'POST', data).then((res) => {
				if (res.statusCode == 200 && res.data.code == 0) {
					this.cuIconList.order[0].badge = res.data.data.needPay;
					this.cuIconList.order[1].badge = res.data.data.completed;
					this.cuIconList.order[2].badge = res.data.data.cancel;
					this.cuIconList.list[0].hasDiscount=res.data.hasCourse;
					this.cuIconList.list[1].hasDiscount = res.data.hasHongbao;
					this.cuIconList.list[2].hasDiscount = res.data.hasDiscount;
					this.dataContrast();


				} else {
					this.Reques.tishi();
				}
			}, (err) => {
				this.Reques.tishi();

			})
		},
		/**
		 * 数据对比
		 */
		dataContrast() {
			uni.getStorage({
				key: 'myinfoList',
				success: (res) => {
					let data = res.data;
					for (let i in data.list) {
						for (let k in this.cuIconList.list) {
							if (data.list[i].title == this.cuIconList.list[k].title && data.list[i]
								.hasDiscount == this.cuIconList.list[k].hasDiscount) {
								this.cuIconList.list[k].showS = data.list[i].showS;
								break;
							}
							if (data.list[i].title == this.cuIconList.list[k].title && data.list[i]
								.hasDiscount != this.cuIconList.list[k].hasDiscount) {
								this.cuIconList.list[k].showS =true;
								break;
							}
						}

					}

					for (let i in data.order) {
						for (let k in this.cuIconList.order) {
							if (data.order[i].name == this.cuIconList.order[k].name && data.order[i]
								.badge == this.cuIconList.order[k].badge) {
								( this.cuIconList.order[k].type!=1)? (this.cuIconList.order[k].showS = data.order[i].showS):"";
								break;
							}
							if (data.order[i].name == this.cuIconList.order[k].name && data.order[i]
								.badge != this.cuIconList.order[k].badge) {
								( this.cuIconList.order[k].type!=1)? (this.cuIconList.order[k].showS = true):"";
								break;
							}
						}

					}
				
				}
		

			})
		},
		/**
		 * 本地数据的对比
		 * 
		 */
		dataStroge() {

			uni.setStorage({
				key: "myinfoList",
				data: this.cuIconList,
				success: () => {
					console.log("存储数据成功");
				},
				fail: () => {
					console.log("失败");
				}

			});
		},
		/**
		 * @param {Object} type
		 */
		jump(type, index) {
			for(let i in this.cuIconList.order){
				(this.cuIconList.order[i].type!=1)?(this.cuIconList.order[i].showS=false):"";
				
			}
			this.dataStroge();
			uni.navigateTo({
				url: '/pages/mycourse/order?type=' + type,
				animationType: 'slide-in-left'
			})

		},
		changeLoagin() {
			//点击登录界面
			uni.navigateTo({
				url: '/pages/login/login',
				animationType: 'slide-in-top'
			});
		},
		
		changeTo(url, index) {
			this.cuIconList.list[index].showS = false;
			this.dataStroge();
			if (url != 0) {
				uni.navigateTo({
					url: url,
					animationType: 'slide-in-left'
				})
			} 
			else {
				uni.clearStorage();
				uni.showLoading({
					title: "正在清除缓存"
				})
				setTimeout(() => {
					uni.hideLoading();
					uni.redirectTo({
						url: '/pages/index/index',
						animationType: "slide-in-left"
					})
				}, 3000);
			}


		},
		
		toChild(e) {
			uni.navigateTo({
				url: e.currentTarget.dataset.url
			})
		},
		/**
		 * 复制我的邀请码
		 */
		copyInitCode() {
			uni.setClipboardData({
				data: this.initCode,
				success: () => {
					uni.showToast({
						title: "复制邀请码成功"
					})
				}
			})


		}









	}


}
